/** 
 * VariableExpression.java
 * @author Lex
 * 2007-8-20 ����04:24:08
 */
package fun.parser.ast.node;

import fun.parser.EvaluationException;
import fun.parser.ast.node.base.Expression;
import fun.parser.lexer.Token;
import fun.symtable.SymbolTable;
import fun.symtable.VariableEntry;

/**
 * ��������
 */
public class VariableExpression extends Expression {
    public VariableExpression(Token node) {
	super(node);
    }

    public String getVariableName() {
	return this.getToken().getImage();
    }

    @Override
    public double getValue(SymbolTable symtable) throws EvaluationException {
	String name = this.getToken().getImage();
	VariableEntry entry = symtable.getVariable(name);
	if (null == entry)
	    entry = symtable.setVariable(name, 0);
	return entry.getValue();
    }
}
